﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：角色管理
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

            // 查看审核
            $('#lr_auth').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'authForm',
                        title: '权限审核 - ' + selectedRow.name,
                        url: config.webportal_server + 'pages/system/role/view.html?keyValue=' + keyValue + '&access_token=' + config.getToken().access_token,
                        width: 850,
                        height: 690,
                        btn: ['审核通过', '取消'],
                        callBack: function (id) {
                            return top[id].acceptClick();
                        }
                    });
                }
            });

        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'roles?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '角色编号', name: 'code', width: 150, align: 'left'},
                    {label: '角色名称', name: 'name', width: 200, align: 'left'},
                    {
                        label: "有效", name: "status", width: 50, align: "center",
                        formatter: function (cellvalue) {
                            return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    {
                        label: "更新时间", name: "updateTime", width: 140, align: "center",
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                    },
                    {label: "角色描述", name: "description", index: "description", width: 300, align: "left"}
                ],
                isPage: true,
                reloadSelected: true,
                mainId: 'id'
            });

            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


